<!-- -->
<template>
  <div class>
    <div class="block">
      <span class="demonstration">开始日期</span>
      <div class="demonstration"></div>
      <el-date-picker
        v-model="startDate"
        type="date"
        placeholder="选择日期"
        format="yyyy 年 MM 月 dd 日"
        value-format="yyyy-MM-dd"
      ></el-date-picker>
    </div>

   <div class="block">
      <span class="demonstration">结束日期</span>
      <div class="demonstration"></div>
      <el-date-picker
        v-model="endDate"
        type="date"
        placeholder="选择日期"
        format="yyyy 年 MM 月 dd 日"
        value-format="yyyy-MM-dd"
      ></el-date-picker>
    </div>


    <div>
      <el-button type="primary" @click="downloadorder">下载订单</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "getOrdersExcels",
  data() {
    return {
      value2:'',
      startDate: "",
      endDate: ""
    };
  },

  components: {},

  filters: {},

  computed: {},

  methods: {

    download(data) {
      if (!data) {
        return;
      }
      let url = window.URL.createObjectURL(new Blob([data]));
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = url;
      link.setAttribute("download", "excel.xlsx");

      document.body.appendChild(link);
      link.click();
    },
    downloadorder() {
      //     var mySelectMonth = this.startDate.getMonth();
      //   var mySelectYear = this.startDate.getFullYear();


      var startDate1 =this.startDate;
      var endDate1 = this.endDate;
      console.log(startDate1);
      console.log(endDate1);
      this.$axios({
        method: "GET",
        url: "/ssms/admin/file/getOrdersExcels",
        params: { startDate: startDate1, endDate:endDate1 },
        responseType: "blob"
      })
        .then(res => {
          console.log(res);
          let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
          let url = window.URL.createObjectURL(blob);
          window.location.href = url;
        })
        .catch(err => {
          console.log(err);
        });

      // this.$axios({
      //   method: "get",
      //   url: "/ssms/admin/file/getOrdersExcels",
      //   data: {
      //     startDate: "2019-09-01",
      //     endDate: "2019-10-19"
      //   },
      //   responseType: "blob"
      // })
      //   .then(response => {
      //     this.download(response);
      //   })
      //   .catch(error => {});

      // this.$axios
      //   .get(
      //     "/ssms/admin/file/getOrdersExcels?startDate=2019-09-01&endDate=2019-10-19",

      //     {
      //       headers: {
      //         responseType: "blob"
      //       }
      //     }
      //   )
      //   .then(res => {
      //     console.log(res);
      //     this.download(res);
      //   });
    }
  }
};
</script>


<style>
</style>
